/* Check blaum_roth_coding_bitmatrix() */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "cauchy-2.h"
#include "jerasure-2.h"
#include "galois-2.h"

using namespace std;

int main( int argc, char** argv )
{
	JER_Matrix *jm;

	int m = atoi( argv[1] );
	int k = atoi( argv[2] );
	int w = atoi( argv[3] );
	int i, j, tmp, fsize;
	IVec X;
	IVec Y;

	fsize = 1 << w;

	if( w < m + k ) return 1;

	srand48(m);
	fprintf( stdout, "X = " );
	for( i = 0; i < m; i++ )
	{
		tmp = lrand48() % fsize;
		for( j = 0; j < i && X[j] != tmp; j++ );
		if( j == i )
		{
			X.push_back(tmp);
			fprintf( stdout, "%d ", X[i] );
		}
		else
			i--;
	}
	fprintf( stdout, "\n" );
	fprintf( stdout, "Y = " );
	for( i = 0; i < k; i++ )
	{
		tmp = lrand48() % fsize;
		for( j = 0; j < m && X[j] != tmp; j++ );
		if( j == m )
		{
			for( j = 0; j < i && Y[j] != tmp; j++ );
			if( j == i )
			{
				Y.push_back(tmp);
				fprintf( stdout, "%d ", Y[i] );
			}
			else
				i--;
		}
		else i--;
	}
	fprintf( stdout, "\n" );
	
	jm = cauchy_xy_coding_matrix( k, m, w, X, Y );

	jm->Print();

	return 0;
}
